#ifndef __THREADPOOL_H__
#define __THREADPOOL_H__

#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <dirent.h>
#include <string.h>
#include <pthread.h>
#include <stdbool.h>
#include <errno.h>

typedef struct Task
{
    void* (*func)(void* arg);//保存函数名
    void* arg;               //保存函数参数
    struct Task* next;      //保存下一个任务结点
}Task;

typedef struct ThreadPool
{
    struct Task* task_list;         //任务队列
    unsigned int waiting_task;      //任务队列中等待的任务数量

    pthread_mutex_t mutex;          //互斥锁，用于保护共享资源
    pthread_cond_t cond;            //条件变量，用于线程同步

    unsigned int active_threads;    //当前活跃的线程数量
    pthread_t* pids;                //线程ID的存储为止（线程ID）

    bool shutdown;                  //线程销毁标准
}ThreadPool;


bool init_pthread_pool(ThreadPool* pool, int thread_num);
void* common_task(void* arg);
bool add_task(ThreadPool* pool, void* (*task)(void*), void* arg);
void threadpool_destroy(ThreadPool* pool);



#endif // !__PTHREADPOOL_H__